<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue组件</title>
    <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>

<body>
    <div id="Application">
        <div>

            <!--
            下面这种是有问题的，会导致不能正常显示，闭合方式必须是 </my-input> ！！！
            <my-input v-model="inputText"/>
            -->

            <!-- 为什么上面的两个组件放在下面组件的下面，将不能正常显示？ -->

            <my-input v-model="inputText"></my-input>
            <div>{{inputText}}</div>
            <button @click="this.inputText=''">清空</button>
        </div>

    </div>
    <script>
        const App = Vue.createApp({
            data() {
                return { inputText: "" }
            },
        })

        const inputComponent = {
            props: ["modelValue"],
            methods: {
                action(event) {
                    console.log(event.target.value)
                    this.$emit('update:modelValue', event.target.value)
                }

            },
            template: `<div>
                <span>输入框：</span>
                <input :value="modelValue" @input="action"/>
            </div>
            `
        }

        App.component("my-input", inputComponent)
        App.mount("#Application") 
    </script>
</body>

</html>